package thread.demo.synchronousQueue;

import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;

public class SynchronousQueue_Take {
  public static void main(String[] args) throws InterruptedException {
    SynchronousQueue synchronousQueue = new SynchronousQueue();
    
    new Thread(() -> {
      try {
        // 如果没有消息的话，一直是等待状态
        System.out.println(synchronousQueue.take());
      } catch (InterruptedException e) {
        throw new RuntimeException(e);
      }
    }).start();
    
    TimeUnit.MILLISECONDS.sleep(100);
    
    new Thread(() -> {
      synchronousQueue.offer("我是消息");
    }).start();
  }
}
